﻿using System;
using System.Collections.Generic;
using System.Text;
using Ex03.VehicalsObjectModel;

namespace Ex03.GarageManagementSystem.Console
{
    internal class VehicalsGarage
    {
        // Members
        private Dictionary<string, GarageVehical> m_Vehicals;

        // Ctor

        /// <summary>
        /// Creates a new vehicals garage
        /// </summary>
        public VehicalsGarage()
        {
            m_Vehicals = new Dictionary<string, GarageVehical>();
        }

        // Properties

        /// <summary>
        /// Gets the vehicals in the garage
        /// </summary>
        public Dictionary<string, GarageVehical>.ValueCollection Vehicals
        {
            get
            {
                return m_Vehicals.Values;
            }
        }

        // Methods

        /// <summary>
        /// Adds a new vehical to the garage
        /// </summary>
        /// <param name="i_Vehical">The Vehical object</param>
        /// <param name="i_OwnersName">The vehicals owners name</param>
        public GarageVehical AddVehical(Vehical i_Vehical, string i_OwnersName)
        {
            // Add the vehical
            GarageVehical addedVehical = new GarageVehical(i_Vehical, i_OwnersName);
            m_Vehicals.Add(i_Vehical.LicenseNumber, addedVehical);

            // Return the new object
            return addedVehical;
        }

        /// <summary>
        /// Removes a vehical from the garage
        /// </summary>
        /// <param name="i_Vehical">The vehical ovbject to remove</param>
        public void RemoveVehical(Vehical i_Vehical)
        {
            // If the vehical exists - remove it
            if (m_Vehicals.ContainsKey(i_Vehical.LicenseNumber))
            {
                m_Vehicals.Remove(i_Vehical.LicenseNumber);
            }
        }
        
        /// <summary>
        /// Gets a vehical of a given license number
        /// </summary>
        /// <param name="i_LicenseNumber">The license number of the vehical</param>
        /// <returns>The vehical with the license number, or null if not exists</returns>
        public GarageVehical GetVehical(string i_LicenseNumber)
        {
            GarageVehical vehical = null;
            if (m_Vehicals.ContainsKey(i_LicenseNumber))
            {
                vehical = m_Vehicals[i_LicenseNumber];
            }

            return vehical;
        }

        /// <summary>
        /// Gets all the vehicals in the garage of the given status
        /// </summary>
        /// <param name="i_filterStatus">The garage status</param>
        /// <returns>A list of garage vehicals</returns>
        public List<GarageVehical> GetVehicalsByStatus(eVehicalStatus i_filterStatus)
        {
            List<GarageVehical> filteredVehicals = new List<GarageVehical>();

            // Go through all the vehicals
            foreach (GarageVehical currVehical in m_Vehicals.Values)
            {
                // If the current vehical is of the wanted status, add it
                if (currVehical.VehicalStatus == i_filterStatus)
                {
                    filteredVehicals.Add(currVehical);
                }
            }

            return filteredVehicals;
        }

        /// <summary>
        /// Gets all the fule vehicals in the garage
        /// </summary>
        /// <returns>A list of garage vehicals</returns>
        public List<GarageVehical> GetFuleVehicals()
        {
            List<GarageVehical> fuleVehicals = new List<GarageVehical>();

            // Go through all the vehicals
            foreach (GarageVehical currVehical in m_Vehicals.Values)
            {
                // If its a fule vehical
                if (currVehical.MaintainedVehical is IFuleVehical)
                {
                    fuleVehicals.Add(currVehical);
                }
            }

            return fuleVehicals;
        }

        /// <summary>
        /// Gets all the electric vehicals in the garage
        /// </summary>
        /// <returns>A list of garage vehicals</returns>
        public List<GarageVehical> GetElectricVehicals()
        {
            List<GarageVehical> electricVehicals = new List<GarageVehical>();

            // Go through all the vehicals
            foreach (GarageVehical currVehical in m_Vehicals.Values)
            {
                // If its an electric vehical
                if (currVehical.MaintainedVehical is IElectricVehical)
                {
                    electricVehicals.Add(currVehical);
                }
            }

            return electricVehicals;
        }
    }
}
